$INCLUDE: 'C:\FG\FASTGRAF.FI'

      PROGRAM MAIN

      INTEGER RECTANGLES
      PARAMETER (RECTANGLES=200)

      INTEGER I
      INTEGER MINX, MAXX, MINY, MAXY
      INTEGER OLD_MODE
      INTEGER XRES, YRES
      INTEGER RANDOM
      INTEGER FG_AUTOMODE, FG_EGACHECK, FG_GETMODE
      INTEGER FG_GETMAXX, FG_GETMAXY

      CALL FG_INITPM
      IF (FG_EGACHECK() .EQ. 0) THEN
         STOP 'This program requires EGA or VGA.'
      END IF

      OLD_MODE = FG_GETMODE()
      CALL FG_SETMODE(FG_AUTOMODE())
      CALL FG_SETFUNC(3)

      XRES = FG_GETMAXX()
      YRES = FG_GETMAXY()

      DO 10 I = 1,RECTANGLES
         MINX = RANDOM(0,XRES)
         MAXX = RANDOM(0,XRES)
         MINY = RANDOM(0,YRES)
         MAXY = RANDOM(0,YRES)
         IF (MINX .GT. MAXX) THEN
            CALL SWAP(MINX,MAXX)
         END IF
         IF (MINY .GT. MAXY) THEN
            CALL SWAP(MINY,MAXY)
         END IF
         CALL FG_SETCOLOR(RANDOM(0,15))
         CALL FG_RECT(MINX,MAXX,MINY,MAXY)
10    CONTINUE

      CALL FG_SETMODE(OLD_MODE)
      CALL FG_RESET

      STOP ' '
      END

      INTEGER FUNCTION RANDOM(MIN,MAX)

      INTEGER MIN, MAX
      INTEGER SEED, TEMP

      DATA SEED /12345/

      TEMP = IEOR(SEED,ISHFT(SEED,-7))
      SEED = IAND(IEOR(ISHFT(TEMP,8),TEMP),#7FFF)
      RANDOM = MOD(SEED,MAX-MIN+1) + MIN

      RETURN
      END

      SUBROUTINE SWAP(VAR1,VAR2)
      INTEGER VAR1, VAR2
      INTEGER TEMP

      TEMP = VAR1
      VAR1 = VAR2
      VAR2 = TEMP

      RETURN
      END

